package com.cirkana;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;

import com.cirkana.serial.SerializablePassData;
import com.cirkana.serial.SerializationException;

public class CirkanaActivity extends Activity {

	public static final int RESULT_CANCEL = -1;
	
	protected static final String DATA_KEY = "data";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Global.setCurrentActivity(this);
		setResult(RESULT_CANCEL);
	}

	protected SerializablePassData getResult() {
		return getPassData(getIntent());
	}

	protected void setResult(int resultCode, SerializablePassData data)
			throws SerializationException {
		Intent result = new Intent();
		setPassData(result, data);
		super.setResult(resultCode, result);
	}
	
	protected void showErrorMessage(Exception e) {
		openMessageBox("Error", e.getMessage());
	}
	
	protected void openMessageBox(String title, String message) {
		AlertDialog alertDialog;
		alertDialog = new AlertDialog.Builder(this).create();
		alertDialog.setTitle(title);
		alertDialog.setMessage(message);
		alertDialog.show();
	}

	public static SerializablePassData getPassData(Intent intent) {
//		return (SerializablePassData) intent.getExtras().getSerializable(
//				DATA_KEY);
		return passData;
	}

	public static void setPassData(Intent intent, SerializablePassData data)
			throws SerializationException {
		//intent.putExtra(DATA_KEY, SerializationUtil.serialize(data));
		passData = data;
	}

	private static SerializablePassData passData;
}
